# Build the webhook binary
FROM golang:1.22.0 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# Copy the go source
COPY main.go main.go
COPY pkg/ pkg/

# Build
# 设置环境变量
ENV CGO_ENABLED=0
ENV GO111MODULE=on
#ENV GOPROXY=https://goproxy.io
ENV GOPROXY="https://goproxy.cn"

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download && \
    go build -a -o admission-registry main.go

FROM alpine:latest
COPY --from=builder /workspace/admission-registry .
ENTRYPOINT ["./admission-registry"]

